<?php require_once 'connect.php'; ?>
<?php 
if ((!empty($_POST['lesson']))&&(!empty($_POST['book']))&&(!empty($_POST['main']))){
	$query="update teach set book='".$_POST['book']."', main='".$_POST['main']."' where lesson_id=".$_POST['lesson']." and teachers_id=".$_SESSION['id'];
	$result=$mysql->query($query);
    if ($result) {
      echo "<script>alert('设定成功！')</script>";
    }else{
      echo "<script>alert('设定失败！')</script>";
    }
}
 ?>
<button type="button" class="btn btn-lg btn-primary" data-toggle="modal" data-target=".bs-setmain-modal-sm">设定课程大纲</button>
<div class="modal fade bs-setmain-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
	    <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="gridSystemModalLabel">设定课程大纲</h4>
        </div>
       	<form action="./" method="post">
        <div class="modal-body">
	        
	        <div class="form-group">
	          <label>课程</label>
	          <select class="form-control" name="lesson">
	          <?php  
	          $query="select id,lesson_name from lessons where id in (select lesson_id from teach where teachers_id=".$_SESSION['id'].")"; 
	          $result=$mysql->query($query);
	          for ($i=1; $i <= $result->num_rows ; $i++) { 
					$row=$result->fetch_assoc();
					echo "<option value=".$row['id'].">".$row['lesson_name']."</option>";
			  }
	          ?>
              </select>
	        </div>

	        <div class="form-group">
	          <label>用书</label>
	          <input type="text" class="form-control" name="book" placeholder="此课程所用书籍">
	        </div>

	        <div class="form-group">
	          <label>课程大纲</label>
	          <textarea class="form-control" rows="8" name="main"></textarea>
	        </div>

      	</div>
     	<div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
          <button type="submit" class="btn btn-primary">保存</button>
        
        </div>
        </form>
    </div>
  </div>
</div>